package org.feidao.chapter65.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * Created by linghufeixia on 2022-12-28.
 * direct config
 */
@Configuration
public class DirectConfig {
    @Bean("direct_exchange_A")
    public DirectExchange directExchangeA() {
        return ExchangeBuilder.directExchange("direct_exchange_A").durable(true).build();
    }

    @Bean("direct_queue_A")
    public Queue directQueueA() {
        return QueueBuilder.durable("direct_queue_A").build();
    }

    @Bean
    public Binding directBindA(@Qualifier("direct_queue_A")Queue queue,
                              @Qualifier("direct_exchange_A")DirectExchange directExchange){
        return BindingBuilder.bind(queue)
                .to(directExchange).withQueueName();
    }

    @Bean("direct_exchange_B")
    public DirectExchange directExchangeB() {
        return ExchangeBuilder.directExchange("direct_exchange_B").durable(true).build();
    }

    @Bean("direct_queue_B")
    public Queue directQueueB() {
        return QueueBuilder.durable("direct_queue_B").build();
    }

    @Bean
    public Binding directBindB(@Qualifier("direct_queue_B")Queue queue,
                               @Qualifier("direct_exchange_B")DirectExchange directExchange){
        return BindingBuilder.bind(queue)
                .to(directExchange).withQueueName();
    }

}
